import pandas as pd
import json

A = pd.read_csv(
    '/Users/lz/PycharmProjects/tianchi/diming_ner/BERT-NER-Pytorch-master/datasets/cnertianchi/final_test.txt',
    sep='\x01', header=None)
A.columns = ['ord', 'sentence']
A['sent_len'] = A['sentence'].apply(len)

# with open('/Users/lz/PycharmProjects/tianchi/diming_ner/'
#           'BERT-NER-Pytorch-master/datasets/cnertianchi/test.char.bieo', 'w+') as f:
#     for i in range(A.shape[0]):
#         sent = A.loc[i, 'sentence']
#         for a in sent:
#             if a.isprintable():
#                 a_ = a
#             else:
#                 a_ = '，'
#             f.write(a_ + ' ' + 'O' + '\n')
#         f.write('\n')

B = pd.read_csv('/Users/lz/PycharmProjects/tianchi/diming_ner/BERT-NER-Pytorch-master/res/test_prediction.json', header=None, sep='\t')
B['tag_ls'] = B[0].apply(lambda x: json.loads(x)['tag_seq'])
B['tag_len'] = B['tag_ls'].apply(lambda x: len(x.split(' ')))

C = pd.concat([A['ord'].reset_index().drop('index', axis=1),
           A['sentence'].reset_index().drop('index', axis=1),
           B['tag_ls']], axis=1, ignore_index=False)

C.to_csv('/Users/lz/PycharmProjects/tianchi/diming_ner/BERT-NER-Pytorch-master/res/003_ddm_addr_parsing_runid.txt',
          header=False, index=False, sep='\x01')